package GUILayer.TableModel;

import java.util.ArrayList;
import java.util.Date;

import javax.swing.table.AbstractTableModel;

import DataLayer.Model.Ordre;

@SuppressWarnings("serial")
public class OrdreTableModel extends AbstractTableModel
{
	private ArrayList<Ordre> li = new ArrayList<Ordre>();
	private String[] columnNames = { "ID", "Oprettelsesdato", "Leveringsdato", "Kunde",
			"Ordrestatus", "Ordretype", "Total pris", "Debit" };

	public OrdreTableModel()
	{
	}

	public void PopulateList(ArrayList<Ordre> list)
	{
		if (list != null)
		{
			this.li = list;
		}
	}

	@Override
	public String getColumnName(int columnIndex)
	{
		return columnNames[columnIndex];
	}

	@Override
	public int getRowCount()
	{
		return li.size();
	}

	@Override
	public int getColumnCount()
	{
		return 8;
	}

	@Override
	public Object getValueAt(int rowIndex, int columnIndex)
	{
		if (li.size() > rowIndex)
		{
			Ordre o = li.get(rowIndex);
			switch (columnIndex)
			{
			case 0:
				return o.getOrdreId();
			case 1:
				return o.getOprettelsesDato();
			case 2:
				return o.getLeveringsDato();
			case 3:
				return o.getKunde().getFornavn() + " " + o.getKunde().getEfternavn();
			case 4:
				return o.getOrdreStatus().toString();
			case 5:
				return o.getOrdreType();
			case 6:
				return o.getTotal();
			case 7:
				return o.getDebit();
			}
		}
		return null;
	}

	@Override
	public Class<?> getColumnClass(int columnIndex)
	{
		switch (columnIndex)
		{
		case 0:
			return int.class;
		case 1:
			return Date.class;
		case 2:
			return Date.class;
		case 3:
			return String.class;
		case 4:
			return String.class;
		case 5:
			return String.class;
		case 6:
			return (li.isEmpty()) ? double.class : getValueAt(0, columnIndex).getClass();
		case 7:
			return (li.isEmpty()) ? double.class : getValueAt(0, columnIndex).getClass();
		}
		return null;
	}
}